package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("menu")
public class MenuController {

    @Reference
    private MenuService menuService;

    @RequestMapping("findAll")
    public Result findAll() {
        try {
            List<Menu> menuList = menuService.findAll();
            return new Result(true, "查询角色数据成功", menuList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询角色数据失败");
        }
    }

    @RequestMapping("findMenuIdsByRoleId")
    public Result findMenuIdsByRoleId(@RequestParam("id") Integer id) {
        try {
            List<Integer> menuIds = menuService.findMenuIdsByRoleId(id);
            return new Result(true, "查询角色数据成功", menuIds);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询角色数据失败");
        }
    }
}
